package com.dfl.ggbond.coldstart;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.dynamicanimation.animation.SpringAnimation;
import androidx.dynamicanimation.animation.SpringForce;

import com.dfl.ggbond.MainActivity;
import com.dfl.ggbond.R;
import com.dfl.ggbond.databinding.ActivityColdStartBinding;
import com.dfl.ggbond.guidepage.GuidePageActivity;

public class ColdStart extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityColdStartBinding binding = ActivityColdStartBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        TextView textView = binding.startText;

        AnimatorSet step1 = new AnimatorSet();
        step1.playTogether(
                ObjectAnimator.ofFloat(textView, "scaleX", 1f, 1.5f).setDuration(400),
                ObjectAnimator.ofFloat(textView, "scaleY", 1f, 1.5f).setDuration(400)
        );
        AnimatorSet step2 = new AnimatorSet();
        step2.playTogether(
                ObjectAnimator.ofFloat(textView, "scaleX", 1.5f, 1f).setDuration(300),
                ObjectAnimator.ofFloat(textView, "scaleY", 1.5f, 1f).setDuration(300)
        );
        AnimatorSet step3 = new AnimatorSet();
        step3.playTogether(
                ObjectAnimator.ofFloat(textView, "scaleX", 1f, 2f).setDuration(500),
                ObjectAnimator.ofFloat(textView, "scaleY", 1f, 2f).setDuration(500)
        );
        AnimatorSet step4 = new AnimatorSet();
        step4.playTogether(
                ObjectAnimator.ofFloat(textView, "scaleX", 2f, 1.5f).setDuration(300),
                ObjectAnimator.ofFloat(textView, "scaleY", 2f, 1.5f).setDuration(300)
        );
        AnimatorSet step5 = new AnimatorSet();
        step5.playTogether(
                ObjectAnimator.ofFloat(textView, "scaleX", 1.5f, 2f).setDuration(400),
                ObjectAnimator.ofFloat(textView, "scaleY", 1.5f, 2f).setDuration(400)
        );
        AnimatorSet all = new AnimatorSet();
        all.playSequentially(step1, step2, step3, step4, step5);
        all.start();

        SharedPreferences sp = getSharedPreferences("demo1", MODE_PRIVATE);
        boolean isFirst = sp.getBoolean("isFirst", true);

        // 延迟跳转，确保动画能显示
        new Handler().postDelayed(() -> {
            if (!isFirst) {
                startActivity(new Intent(this, MainActivity.class));
            } else {
                startActivity(new Intent(this, GuidePageActivity.class));
            }
            finish();
        }, 1900);
    }
}